package com.dashboard.tuyensinh;

import java.sql.ResultSet;

import com.lb.jwitter.connectDatabase.ConnectTuyenSinh;
import com.opensymphony.xwork2.Action;

public class BacDHVungMienAction {
	private String jsonData;
	public String getJsonData() {
		return jsonData;
	}


	public void setJsonData(String jsonData) {
		this.jsonData = jsonData;
	}
	////////////////////////////////////////////////////////
	private String namHoc;

	public String getNamHoc() {
		return namHoc;
	}


	public void setNamHoc(String namHoc) {
		this.namHoc = namHoc;
	}
	/////////////////////////////////////////////////////////
	
	public String execute() throws Exception
	{
		ConnectTuyenSinh connection= new ConnectTuyenSinh();
		if(connection.getConnection()!=null){
			//namHoc="2014";
			
			if(namHoc==null||namHoc.length()<1){
				return Action.ERROR;
			}
			
			String query="select sum( B.soSV) as soSV, C.ten as vungmien"
					+" from tinhthanh A,"
					+" (select distinct soSV, tinhthanh_id from tuyensinh_tinhthanh where nam="+namHoc+" and bacdaotao_id=1) B,"
					+" vungmien C"
					+" where A.id=B.tinhthanh_id and A.vungmien_id=C.id"
					+" group by A.vungmien_id, C.ten";
			ResultSet data=connection.getData(query);
			if(data!=null){
				jsonData="[";
				while(data.next()){
					String vungmien=data.getString("vungmien");
					int soSV=data.getInt("soSV");
					jsonData=jsonData+"{\"vungmien\":\""+vungmien+"\",\"soSV\":"+soSV+"},";
				}
				jsonData=jsonData+"]";
				jsonData=jsonData.replaceAll(",]", "]");
				//[{"soSV":"5000","vungmien":"Tay Nguyen"}]
			}
			
			
			
			
		}
		connection.closeConnection();
		return Action.SUCCESS;

	}
}
